{include_core file="lib/header.html" title="我的订单" center="center"}
{include_core file="lib/top_nav.html"}
<div class="container">
  <div class="inner">
    <div class="con-top clearfix">
      {include_core file="lib/sidebar.html" crumbs_1="center" crumbs_2="order"}
      <div class="myorder clearfix">
        <div class="myorder-top clearfix">
          <h4>我的订单</h4>
          <ul class="clearfix">
            <li {if !$progress}class="curr"{/if}><a href="{AnUrl('order')}">全部订单</a>　|　</li>
            <li {if $progress==1}class="curr"{/if}><a href="{AnUrl('order?progress=1')}">待付款<span>{order_helper::get_order_total(1)}</span></a>　|　</li>
            <li {if $progress==10}class="curr"{/if}><a href="{AnUrl('order?progress=10')}">待发货<span>{order_helper::get_order_total(10)}</span></a>　|　</li>
            <li {if $progress==15}class="curr"{/if}><a href="{AnUrl('order?progress=15')}">待收货<span>{order_helper::get_order_total(15)}</span></a>　|　</li>
            <li {if $progress==20}class="curr"{/if}><a href="{AnUrl('order?progress=20')}">已完成</a></li>
          </ul>
        </div>

        {widget model="order" func="get_list" file="order_list.html" per_page=10 progress=$progress}
      </div>

    </div>
    <!--con-top  end-->
    {widget model="goods" func="get_star_list" file="star_list.html" per_page=4}
  </div>
  <!--inner  end-->
</div>
<!--container  end-->
<script>
  $(function(){
    /**
     * 确认收货
     */
    $('.js_sureReceiver').on('click', function(){
      var url = siteUrl+'/order/sure_receive';
      var id = $(this).data('order_id');

      if (btnClick() === false) {
        return false;
      }
      showConfirm('您确定已经收到商品了吗？', function(){
        $.post(url, { id:id }, function(json){
          if (json.info == 'ok') {
            window.location.href = window.location.href;
          } else {
            showMsg(json.info);
            btnClick('reset');
          }
        }, 'json');
      })
    });

    /**
     * 再次加入购物车
     */
    $('.js_replayToCart').on('click', function(){
      var parentLi = $(this).closest('li');
      parentLi.find('dl').each(function(){
        var skuId    = $(this).data('sku_id');
        var goodsNum = $(this).data('goods_num');
        var is_gift  = $(this).data('is_gift');
        var is_promotion = $(this).data('is_promotion');
        if(is_promotion== 0 && is_gift == 0) {
          window.location.href= $(this).find('.js_openLink').data('href');
          return false;
        }
        
        // liw mod
        /* addGoodsToCart(skuId, goodsNum, function(info){
          console.log(info);
          setTimeout(function(){
            location.href = siteUrl+'/cart';
          }, 1000);
        }, is_promotion, is_gift); */
      });
      /* showMsg('添加商品到购物车，请稍等...'); */
    });

    /**
     * 取消订单
     */
    $('.js_cancelOrder').on('click', function(){
      var orderId = $(this).data('order_id');
      $('.js_cancelOrderConfirm').show().prev().show();
      $('.js_cancelOrderConfirm').data('order_id', orderId);
    });

    $('.js_cancelBtn').on('click', function(){
      $('.js_cancelOrderConfirm').hide().prev().hide();
    });

    $('.js_submitBtn').on('click', function(){
      var reason  = $('#js_cancelOrderReason').val();
      var orderId = $('.js_cancelOrderConfirm').data('order_id');
      var url     = siteUrl+'/order/cancel_order';
      
      if (reason == 0) {
        showMsg('请选择原因');
        return;
      }
      if (btnClick() == false) {
        return false;
      }
      $.post(url, { order_id:orderId, reason:reason }, function(json){
        if (json.info == 'ok') {
          location.href = location.href;
        } else {
          showMsg(json.info, 'error');
          btnClick('reset');
        }
      }, 'json');
    });
  });
</script>
{include_core file="lib/footer.html"}